<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<p>对象</p>
<div id="res"></div>
<p>数组</p>
<div id="res1"></div>
<p>新闻</p>
<div id="news"></div>
<script src="../news.js" type="text/javascript"></script>
<script type="text/javascript">
    //json 对象 {"name":"张三"}  各种平台之间数据传输

    //1.对象 键值对 key:val,key1:val1,key2:val2....keyn:valn
    let json1 = {
        "name": "admin",
        "age": 20,
        "birthday": "1999-10-10"
    };

    var str = "";
    str += "姓名:" + json1.name + "<br>";
    str += "年龄:" + json1.age + "<br>";
    str += "出生日期:" + json1.birthday + "<br>";
    document.getElementById("res").innerHTML = str;

    //2.数组  对象数组
    let json2 = [{
        "name": "admin",
        "age": 20,
        "birthday": "1999-10-10"
        },
        {
            "name": "test",
            "age": 22,
            "birthday": "1997-10-10"
        },
        {
            "name": "张三",
            "age": 21,
            "birthday": "1998-10-10"
        }];
    //对象点属性

    //循环
    var strArr = "";
    for (let o of json2) {
        strArr += "姓名:" + o.name + "<br>";
        strArr += "年龄:" + o.age + "<br>";
        strArr += "出生日期:" + o.birthday + "<br>";
    }
    document.getElementById("res1").innerHTML = strArr;

    //对象数组
    let newsStr = "";
    for (let news of newsJson.result.data) {
        newsStr += "标题:" + news.title + "<br>";
        newsStr += "日期:" + news.date + "<br>";
        newsStr += "分类:" + news.category + "<br>";
        newsStr += "来自:" + news.author_name + "<br>";
        newsStr += "详情:<a href='" + news.url + "'>详情</a><br>";
        newsStr += "图片:<img src='" + news.thumbnail_pic_s + "'<br><br>";
    }
    document.getElementById("news").innerHTML = newsStr;


   window.onload  = function () {
        alert("页面加载完成:" + document.getElementById("news").innerHTML);
    }
</script>
</body>
</html>